﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows;

namespace WPFConsole
{
    public partial class PConsole : Window
    {


        void ConnectCommand(string[] args)
        {
            string IP = "";
            try
            {
                IP = args[Array.IndexOf(args, "-connect") + 1];
            }
            catch (IndexOutOfRangeException)
            {
                this.WriteLine("Error processing command-line information for -connect");
            }
            this.PreMadeInput("connect " + IP);
            if (((IList<string>)args).Contains("-login") && !NeedToStopParsingArgs)
            {
                NeedToStopParsingArgs = true;
                LoginCommand(args);
            }

        }

        void LoginCommand(string[] args)
        {
            string uname = "";
            string pass = "";
            try
            {
                uname = args[Array.IndexOf(args, "-login") + 1];
                pass = args[Array.IndexOf(args, "-login") + 2];
            }
            catch (IndexOutOfRangeException)
            {
                this.WriteLine("Error processing command-line information for -login");
            }
            if (((IList<string>)args).Contains("-connect") && NeedToStopParsingArgs)
            {
                this.PreMadeInput(("login " + uname + " " + pass));
            }
            else if (((IList<string>)args).Contains("-connect") && !NeedToStopParsingArgs)
            {
                ConnectCommand(args);
            }
            else if (!((IList<string>)args).Contains("-connect"))
            {
                this.WriteLine("Cannot use the login command line argument without the connect argument.");
            }
        }
    }
}
